package com.example.easybuy.controller;


import com.alibaba.fastjson.JSON;
import com.example.easybuy.pojo.EasybuyNews;
import com.example.easybuy.service.EasybuyNewsService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 张子晨
 * @since 2021-03-12
 */
@RestController
@RequestMapping("/easybuyNews")
public class EasybuyNewsController {

    @Autowired
    EasybuyNewsService easybuyNewsService;

    @RequestMapping("/newsLatest")
    public String newsLatest() {
        List<EasybuyNews> list = easybuyNewsService.newsLatest();
        System.out.println("----------------" + JSON.toJSONString(list));
        return JSON.toJSONString(list);
    }

    @RequestMapping("/allNews")
    public String allNews(String pageNum, String pageSize) {
        PageInfo<EasybuyNews> pageInfo = easybuyNewsService.newsAll(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
        return JSON.toJSONString(pageInfo);
    }

    @RequestMapping("/newsById")
    public Object getNewsById(String id) {
        EasybuyNews easybuyNews = easybuyNewsService.getNewsById(Integer.parseInt(id));
        return easybuyNews;
    }

}

